package com.teacherprofile.manage.controller;

import java.util.List;

import com.teacherprofile.common.utils.StringUtils;
import com.teacherprofile.manage.domain.dto.TechSpecialistExportDTO;
import jakarta.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.teacherprofile.common.annotation.Log;
import com.teacherprofile.common.core.controller.BaseController;
import com.teacherprofile.common.core.domain.AjaxResult;
import com.teacherprofile.common.enums.BusinessType;
import com.teacherprofile.common.domain.TechSpecialist;
import com.teacherprofile.manage.service.ITechSpecialistService;
import com.teacherprofile.common.utils.poi.ExcelUtil;
import com.teacherprofile.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 科技特派员Controller
 * 
 * @author vibelin
 * @date 2025-05-17
 */
@Api(tags = "科技特派员")
@RestController
@RequestMapping("/manage/specialist")
public class TechSpecialistController extends BaseController
{
    @Autowired
    private ITechSpecialistService techSpecialistService;

    /**
     * 查询科技特派员列表
     */
    @ApiOperation(value = "查询科技特派员列表")
    @PreAuthorize("@ss.hasPermi('manage:specialist:list')")
    @GetMapping("/list")
    public TableDataInfo list(TechSpecialist techSpecialist)
    {
        startPage();
        List<TechSpecialist> list = techSpecialistService.selectTechSpecialistList(techSpecialist);
        return getDataTable(list);
    }

    /**
     * 导出科技特派员列表
     */
    @ApiOperation(value = "导出科技特派员列表")
    @PreAuthorize("@ss.hasPermi('manage:specialist:export')")
    @Log(title = "科技特派员", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TechSpecialistExportDTO dto)
    {
        List<TechSpecialist> list = techSpecialistService.selectTechSpecialistList(dto);
        ExcelUtil<TechSpecialist> util = new ExcelUtil<TechSpecialist>(TechSpecialist.class);
        util.exportEasyExcel(response, list, "科技特派员数据", StringUtils.str2List(dto.getExportFields(), ",", true, true));
    }

    /**
     * 获取科技特派员详细信息
     */
    @ApiOperation(value = "获取科技特派员详细信息")
    @PreAuthorize("@ss.hasPermi('manage:specialist:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(techSpecialistService.selectTechSpecialistById(id));
    }

    /**
     * 新增科技特派员
     */
    @ApiOperation(value = "新增科技特派员")
    @PreAuthorize("@ss.hasPermi('manage:specialist:add')")
    @Log(title = "科技特派员", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TechSpecialist techSpecialist)
    {
        return toAjax(techSpecialistService.insertTechSpecialist(techSpecialist));
    }

    /**
     * 修改科技特派员
     */
    @ApiOperation(value = "修改科技特派员")
    @PreAuthorize("@ss.hasPermi('manage:specialist:edit')")
    @Log(title = "科技特派员", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TechSpecialist techSpecialist)
    {
        return toAjax(techSpecialistService.updateTechSpecialist(techSpecialist));
    }

    /**
     * 删除科技特派员
     */
    @ApiOperation("删除科技特派员")
    @PreAuthorize("@ss.hasPermi('manage:specialist:remove')")
    @Log(title = "科技特派员", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(techSpecialistService.deleteTechSpecialistByIds(ids));
    }

    /**
     * 导入科技特派员
     * @param file
     * @return
     * @throws Exception
     */
    @ApiOperation("导入科技特派员")
    @Log(title = "导入管理", businessType = BusinessType.IMPORT)
    @PreAuthorize("@ss.hasPermi('system:specialist:import')")
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file) throws Exception {
        ExcelUtil<TechSpecialist> util = new ExcelUtil<TechSpecialist>(TechSpecialist.class);
        List<TechSpecialist> techSpecialist = util.importEasyExcel(file.getInputStream());
        String message = techSpecialistService.importData(techSpecialist);
        return success(message);
    }

    /**
     * 审批
     */
    @ApiOperation(value = "科技特派员审批")
    @PreAuthorize("@ss.hasPermi('manage:specialist:check')")
    @Log(title = "科技特派员", businessType = BusinessType.UPDATE)
    @PutMapping("/check")
    public AjaxResult check(@RequestBody TechSpecialist techSpecialist) {
        return toAjax(techSpecialistService.check(techSpecialist));
    }
}
